<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace app\index\controller;
use app\common\controller\Base;
use think\Db;
use utils\Page;
/**
 * @title 图片
 */
class Pic extends Base{
    /**
     * @title 美女图集
     */
    public function views($id = 0) {
//        {
//  "title": "", //相册标题
//  "id": 123, //相册id
//  "start": 0, //初始显示的图片序号，默认0
//  "data": [   //相册包含的图片，数组格式
//    {
//      "alt": "图片名",
//      "pid": 666, //图片id
//      "src": "", //原图地址
//      "thumb": "" //缩略图地址
//    }
//  ]
//}
        if ($id) {
            $api_url = 'http://api.mmno.com/api/mmphoto/details?id=' . $id;
            $result_json = curl_request($api_url);
            $result = json_decode($result_json, true);
            $tmp_arr = array();
            foreach ($result['data'] as $key => $value) {
                $tmp_arr['data'][] = array(
                    'alt' => '',
                    'pid' => $key,
                    'src' => $value,
                    'thumb' => $value,
                );
            }
            $tmp_arr['title'] = '';
            $tmp_arr['id'] = $id;
            $tmp_arr['start'] = 0;
            echo json_encode($tmp_arr);
        }
    }
    /**
     * @title 美女瀑布
     */
    public function lists() {
        $page = input('get.page', 1);
        $page_size = 10;
        $api_url = 'http://api.mmno.com/api/mmphoto/index?type=4&page=' . $page . '&rows=' . $page_size;
        $result_json = curl_request($api_url);
        $result = json_decode($result_json, true);
        
        
        
        
        $page = new Page();
        
        $url = url('index/pic/lists') . '?page={page}';
        
        $page->setUrl($url);
        $page->setTotal($result['total']);
        $page->setLimit($page_size);
        
        
        $this->assign('page', $page->render());
        $this->assign('list', $result['data']);
        // print_r($result);exit;
        //SEO
        $seo_array['title'] = '美女瀑布流 - ';
        $seo_array['keywords'] = '美女瀑布流';
        $seo_array['description'] = '美女瀑布流';
        $this->assign('seo', $seo_array);
        return $this->fetch();
    }
}
